﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using DailyDiet.Services;
using DailyDiet.Services.Constant;
using DailyDiet.Services.Impl;
using Moq;
using NUnit.Framework;

namespace DailyDietTest.Helper
{
    public static class GetRecServiceTestHealper {
        private static IGetRecService _getRecServiceNotRec;
        private static IGetRecService _getRecServiceDoRec;
        public static async Task<IGetRecService> GetInitializedGetRecServiceNotRec() {
            if (_getRecServiceNotRec != null) {
                return _getRecServiceNotRec;
            }
            IRecommendService recommendService = RecommendServiceImplHealper
                .GetInitializedRecommendServiceImpl();

            var preferenceMock = new Mock<IPreferenceStorage>();
            preferenceMock
                .Setup(p =>
                    p.Get(GetRecServiceConstant.DinnerTimeKey, GetRecServiceConstant.DefaultDateTime))
                .Returns(DateTime.Now.AddDays(-1));
            preferenceMock
                .Setup(p =>
                    p.Get(GetRecServiceConstant.LunchTimeKey, GetRecServiceConstant.DefaultDateTime))
                .Returns(DateTime.Now.AddDays(-1));
            preferenceMock
                .Setup(p =>
                    p.Get(GetRecServiceConstant.BreakfastTimekey, GetRecServiceConstant.DefaultDateTime))
                .Returns(DateTime.Now.AddDays(-1));

            IPreferenceStorage preference = preferenceMock.Object;

            IDietStorageService dietStorageService =
                await DietStorageServiceTestHelper.getIntializedDietStorageService();

            ICacheSerializeService cacheSerializeService =
                new CacheSerializeService();
            _getRecServiceNotRec = new GetRecService(dietStorageService, recommendService, preference, cacheSerializeService);
            return _getRecServiceNotRec;
        }


        public static async Task<IGetRecService> GetInitializedGetRecServiceDoRec()
        {
            if (_getRecServiceDoRec != null) {
                return _getRecServiceDoRec;
            }
            
            IRecommendService recommendService = RecommendServiceImplHealper
                .GetInitializedRecommendServiceImpl();

            var preferenceMock = new Mock<IPreferenceStorage>();
            preferenceMock
                .Setup(p =>
                    p.Get(GetRecServiceConstant.DinnerTimeKey, GetRecServiceConstant.DefaultDateTime))
                .Returns(DateTime.Now.AddDays(1));

            preferenceMock
                .Setup(p =>
                    p.Get(GetRecServiceConstant.LunchTimeKey, GetRecServiceConstant.DefaultDateTime))
                .Returns(DateTime.Now.AddDays(1));

            preferenceMock
                .Setup(p =>
                    p.Get(GetRecServiceConstant.BreakfastTimekey, GetRecServiceConstant.DefaultDateTime))
                .Returns(DateTime.Now.AddDays(1));

            IPreferenceStorage preference = preferenceMock.Object;

            IDietStorageService dietStorageService =
                await DietStorageServiceTestHelper.getIntializedDietStorageService();

            ICacheSerializeService cacheSerializeService =
                new CacheSerializeService();
            _getRecServiceDoRec = new GetRecService(dietStorageService, recommendService, preference, cacheSerializeService);
            return _getRecServiceDoRec;
        }
    }
}
